<?php

namespace App\Kuafu\Export\Service\ExportFactory;

use App\Kuafu\Statistics\Service\StatisticsService;
use Illuminate\Support\Str;

/**
 * app-堂食订单明细
 */
class ExportAppInOrderService extends BaseExportService
{
    private string $localPath = '';

    public function query(): self
    {
        $shopId          = (int)($this->params['shopId'] ?? 0);
        $startAt = date('Y-m-d H:i:s', $this->params['showStartAt'] ?? time());
        $endAt   = date('Y-m-d H:i:s', $this->params['showEndAt'] ?? time());
        $this->localPath = sys_get_temp_dir() . '/' . Str::random();

        StatisticsService::shopOrderExcel($shopId, 0, 0, $startAt, $endAt, $this->localPath);

        return $this;
    }

    public function path(): string
    {
        return $this->upload($this->localPath);
    }
}
